home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Prograph Classic 2.6.1 / Examples / Super_System_Classes / Scrollbar ƒ / source ƒ / scroll_proc.c next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  4.0 KB  |  151 lines  |  [TEXT/KAHL]

  1. /*change this flag to 0 for the compiler, 1 for the interpreter */
  2. #define _INTERPRETER 1
  3.  
  4. #include "Controls.h"
  5. #include "X_constants.h"
  6. #include "X_data_types.h"
  7. #include "X_prim_structs.h"
  8. #include "X_mac_structs.h"
  9. #include "X_sys_structs.h"
  10. #include "X_struct_ids.h"
  11. #include "X_prototypes.h"
  12. #include "X_macros.h"
  13. #include "scroll_proc.h"
  14.  
  15. /* This file contains a call back for the control manager, two XPRIMs and the code    */
  16. /* to install them in the interpreter environment.    It is for use with the Scroll    */
  17. /* Bar example class, but it also demonstrates how to use C code to do callbacks    */
  18. /* with Prograph.                                                                    */
  19.  
  20. /* List of Routines:
  21.         PGScrollAction     - This is the call back that is used by the control manager.
  22.         scroll-proc        - Outputs the address of PGScrollAction.
  23.         inst-to-addr    - Outputs the address of the instance that is input.
  24. */
  25.     
  26. #if _INTERPRETER
  27.     ProcPtr * ct;
  28. #endif
  29.  
  30.  
  31. /* PGScrollAction - This is a callback routine is used by the control manager to     */
  32. /*                    handle clicks in the various parts of the control.    If the user    */
  33. /*                    clicks in the UpButton or DownButton, this routine uses the     */
  34. /*                    value of the line pixel attribute of the Prograph instance        */
  35. /*                    bound to this control record.  If the user clicks in the UpPage    */
  36. /*                    DownPage part of the control, then this routine uses the value    */
  37. /*                    of the page pixel attribute of the Prograph instance bound to     */
  38. /*                    this control record.                                            */
  39.  
  40.  
  41. pascal void PGScrollAction
  42. ControlHandle    control,                    /* effect control */
  43. Int2            part                         /* control part */
  44. )
  45. {
  46. Int4             value;                        /* control's value */
  47. Int2            min;
  48. Int2            max;
  49. C_Scroll_20_Bar    *inst;
  50. C_integer        *line;
  51. C_integer        *page;
  52.  
  53.     value = GetCtlValue( control );
  54.     min = GetCtlMin( control );
  55.     max = GetCtlMax( control );
  56.     
  57.     inst = (Handle)GetCRefCon( control );
  58.     
  59.     line = (*inst)->line_pix;
  60.     page = (*inst)->page_pix;
  61.     
  62.     switch( part )
  63.     {
  64.         case inUpButton:
  65.             value -= (*line)->value;
  66.             break;
  67.         case inDownButton:
  68.             value += (*line)->value;
  69.             break;
  70.         case inPageUp:
  71.             value -= (*page)->value;
  72.             break;
  73.         case inPageDown:
  74.             value += (*page)->value;
  75.             break;
  76.         default:
  77.             return;
  78.     }
  79.     
  80.     if( value < min )
  81.         value = min;
  82.     if( value > max )
  83.         value = max;
  84.  
  85.     SetCtlValue( control, (Int2)value );
  86. }
  87.  
  88. /* scroll-proc    -    This routine takes a part code as input.  If the part code        */
  89. /*                    indicates that the user clicked in the thumb of the control        */
  90. /*                    then ZERO is returned.  Otherwise, if the user clicked in any    */
  91. /*                    other part of the control, this XPRIM returns the address of    */
  92. /*                    the callback routine PGScrollAction.  This is necessitated        */
  93. /*                    by the structure of the control manager.  A callback used by    */
  94. /*                    the control manager when the user clicks in the thumb of a        */
  95. /*                    control does not have any parameters. A callback used when the    */
  96. /*                    user clicks in some other part of the control has two            */
  97. /*                    parameters.  Thus, when the user clicks in the thumb of the     */
  98. /*                    control, this XPRIM passes out 0 so that TrackControl will take    */
  99. /*                    the default action.                                                */
  100.  
  101. Nat2 U_scroll_2D_proc
  102. (
  103. C_integer        *cSPart,            /* Part Code */
  104. C_integer        **cSProc            /* Address of scroll proc */
  105. )
  106. {
  107.  
  108. #if _INTERPRETER
  109. {
  110.     Nat2 inarity, outarity;
  111.     
  112.     GETARITY( inarity, outarity);
  113.     
  114.     if( inarity != 1 && outarity != 1 )
  115.         return PRIMERR_ARITY;
  116. }
  117. #endif 
  118.         
  119.     if( (*cSPart)->value != 0 && (*cSPart)->value != inThumb )
  120.         *cSProc = MakeC_integer( (Int4)(&PGScrollAction) );
  121.     else 
  122.         *cSProc = MakeC_integer( (Int4)0 );
  123.         
  124.     return PCF_TRUE;
  125. }
  126.  
  127. #if _INTERPRETER
  128.  
  129. /* main loads primitives into prograph interpreter's primitive table */
  130.  
  131. void main( table )
  132.  
  133. ProcPtr * table;                /* common table */
  134.  
  135. {
  136.     asm 
  137.     { 
  138.         move.l a4, -(sp)         /* move A4 on to the stack */
  139.         move.l a0, a4            /* move address of code resource to A4 */
  140.     }
  141.     
  142.     ct = table;                    /* set up common table for shared functions */
  143.     
  144.     AddPrimitive( 1, 0x0101, PF_USER, 0, &U_scroll_2D_proc );
  145.  
  146.     asm { move.l (sp)+, a4 }    /* move saved value back into A4 */
  147. }
  148.  
  149. #endif
  150.